package com.vietnam.power.persitence;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.vietnam.power.domain.Root;

/**
 * The persistent class for the article database table.
 * 
 */
@Entity
@Table(name = "article")
public class Article implements Serializable, Root {
	private static final long serialVersionUID = 1L;
	private int id;
	private Date createdDate;
	private String description;
	private String embededMap;
	private String keyword;
	private String name;
	private String shortDescription;
	private ArticleGroup articleGroup;
	private UserInfo userInfo;
	private List<ArticleImage> articleImages;
	private String email;
	private String password;

	public Article() {
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "created_date")
	public Date getCreatedDate() {
		return this.createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	@Lob
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Lob
	@Column(name = "embeded_map")
	public String getEmbededMap() {
		return this.embededMap;
	}

	public void setEmbededMap(String embededMap) {
		this.embededMap = embededMap;
	}

	public String getKeyword() {
		return this.keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Lob
	@Column(name = "short_description")
	public String getShortDescription() {
		return this.shortDescription;
	}

	public void setShortDescription(String shortDescription) {
		this.shortDescription = shortDescription;
	}

	// bi-directional many-to-one association to ArticleGroup
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "article_group_id")
	public ArticleGroup getArticleGroup() {
		return this.articleGroup;
	}

	public void setArticleGroup(ArticleGroup articleGroup) {
		this.articleGroup = articleGroup;
	}

	// bi-directional many-to-one association to UserInfo
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "created_by")
	public UserInfo getUserInfo() {
		return this.userInfo;
	}

	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;
	}

	// bi-directional many-to-one association to ProductImage
	@OneToMany(mappedBy = "article", cascade = CascadeType.ALL, orphanRemoval = true)
	public List<ArticleImage> getArticleImages() {
		if (this.articleImages == null) {
			this.articleImages = new ArrayList<ArticleImage>();
		}
		return this.articleImages;
	}

	public void setArticleImages(List<ArticleImage> articleImages) {
		this.articleImages = articleImages;
	}

	public ArticleImage addArticleImage(ArticleImage productImage) {
		getArticleImages().add(productImage);
		productImage.setArticle(this);

		return productImage;
	}

	public ArticleImage removeArticleImage(ArticleImage productImage) {
		getArticleImages().remove(productImage);
		productImage.setArticle(this);

		return productImage;
	}
}